package codingforgreat.lchot150;

public class Lc069 {
    public int mySqrt(int x) {
        if(x == 0){
            return 0;
        }else if(x < 3){
            return 1;
        }else{
            long ans = 1;
            long L = 1;
            long R = x;
            long M = 0;
            while (L <= R) {
                M = (L + R) / 2;
                if (M * M <= x) {
                    ans = M;
                    L = M + 1;
                } else {
                    R = M - 1;
                }
            }
            return (int) ans;
        }

    }
}
